/*
 * <one line to give the program's name and a brief idea of what it does.>
 * Copyright (C) 2019
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef DATATABLE_H
#define DATATABLE_H

#include "commondata.hpp"

/**
 * \class DataTable
 * \brief Run time calculated tables
 *
 * This is static only class for tables with precalculated data.
 * Needed for speed up program and skip unnecessary computations
 */

class DataTable {
public:
	/**
	 * \brief calculate and fill tables
	 *
	 * This function calculate all values need to fill tables
	 * This function must be called before any calculations!!! 
	 */
	static void init();

	static resource dronePrice[tableSize::drone];							//*< array with drone upgrading price for each level  */
	static resource dronePriceTotal[tableSize::drone];						//*< array with total drone upgrading price for each level  */
	static double droneStats[tableSize::drone][6];							//*< array with drone stats for every type and level */
	static uint32_t dronePower[tableSize::drone];							//*< array with drone power for each level , needed for trophy points calculation */

	static resource upgradePrice[tableSize::upgrade];						//*< array with ship part upgrading price for each level  */
	static resource upgradePriceTotal[tableSize::upgrade];					//*< array with total ship part upgrading price for each level */
	static double upgradeStats[tableSize::upgrade][4];						//*< array with part values for each type and level */

	static double aiStats[tableSize::ai][4];								//*< array with ai ship stats for each level and type */
	static resource aiReward[tableSize::ai];								//*< array with reward for destroy ai ship for each level */
	static resource aiRewardTotal[tableSize::ai];							//*< array with total reward for destroy ai ship for each level */

	static uint32_t trophy[tableSize::ai];									//*< array with trophy points gained for each trophy level */
	static uint32_t trophyTotal[tableSize::ai];								//*< array with total trophy points gained for each trophy level */

	static uint32_t power[tableSize::upgrade];								//*< array with power points gained for each level of ship part or drone */
	static uint32_t powerTotal[tableSize::upgrade];							//*< array with total power points gained for each level of ship part or drone */

	static uint32_t trophyPrice[tableSize::trophy];							//*< array with tropy upgrading price for each level *>
	static uint32_t trophyPriceTotal[tableSize::trophy];					//*< array with total tropy upgrading price for each level *>

private:
	/**
	 * calculate upgrading price for ship part to current level
	 * \param[in] level upgrade level
	 * \return how many resources needed to upgrading
	 */
	static resource formulaUpgrade(const uint16_t & level);

	/**
	 * calculate upgrading price for drone to current level
	 * \param[in] level drone level
	 * \return how many resources needed to upgrading
	 */
	static resource formulaDrone(const uint8_t & level);

	/**
	 * fill droneStats with drone stats for current level
	 * \param[in] level drone level
	 * \param[out] data pointer to array
	 */
	static void formulaDroneValue(const uint8_t & level, double * data);

	/**
	 * calculate ship speed for current level
	 * \param[in] level wings level
	 * \return ship speed
	 */
	static double formulaWings(const uint16_t & level);

	/**
	 * calculate ship damage
	 * \param[in] level weapon level
	 * \return ship damage
	 */
	static double formulaWeapon(const uint16_t & level);

	/**
	 * calculate ship shield
	 * \param[in] level reactor level
	 * \return ship shield
	 */
	static double formulaShield(const uint16_t & level);

	/**
	 * calculate ship hp
	 * \param[in] level hull level
	 * \return ship hp
	 */
	static double formulaHull(const uint16_t & level);

	/**
	 * fill aiStats with ai ship stats for current level
	 * \param[in] level ai ship level
	 * \param[out] data pointer to double[4] array
	 */
	static void formulaAiStats(const uint16_t & level, double * data);

	/**
	 * calculate trophy points for current trophy level
	 * \param[in] level trophy level
	 * \return trophy points gained for this level
	 */
	static uint32_t formulaTrophy(const uint16_t & level);

	/**
	 * calculate power for ship part or drone for current level
	 * \param[in] level
	 * \param[in] drone true if drone, false if ship part. default is ship part
	 * \return power gained from this level
	 */
	static uint32_t formulaPower(const uint16_t & level, bool drone = false);

	/**
	 * calculate reward for destroy ai ship on current level
	 * \param[in] level aiu ship level
	 * \return how many resources u will get
	 */
	static resource formulaReward(const uint32_t & level);

	/**
	 * calculate trophy upgrading price for current level
	 * \param[in] level upgrade level
	 * \return amount of trophy points needed to upgrade
	 */
	static uint32_t formulaTrophyPrice(const uint32_t & level);
};

#endif // DATATABLE_H
